package com.zhaorui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhaorui.component.BusinessException;
import com.zhaorui.entity.ActivityUser;
import com.zhaorui.form.ModifyPassForm;
import com.zhaorui.mapper.AccountMapper;
import com.zhaorui.service.ActivityUserService;
import com.zhaorui.mapper.ActivityUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.*;
import java.util.HashMap;
import java.util.List;

/**
 *
 */
@Service
public class ActivityUserServiceImpl extends ServiceImpl<ActivityUserMapper, ActivityUser>
        implements ActivityUserService {
    @Autowired
    private ActivityUserMapper activityUserMapper;


    //综合查询
    @Override
    public List<HashMap> queryUsers( ActivityUser activityUser) {
        return activityUserMapper.queryUsers (activityUser);
    }

    @Override
    //查询所有
    public List<HashMap> queryUsersAll() {
        return activityUserMapper.queryUsersAll();
    }

    //根据id查询
    @Override
    public ActivityUser queryUsersId(Integer id) {
        return activityUserMapper.queryUsersId(id);
    }

    //新增
    @Override
    public void saveUser(ActivityUser activityUser) {
        //添加时姓名不能重复
        QueryWrapper wrapper = new QueryWrapper ();
        wrapper.eq ("user_name", activityUser.getUserName ());
        Integer count = this.baseMapper.selectCount (wrapper);
        if (count > 0) {//抛出异常
            throw new BusinessException ("账号重复，添加失败！");
        }
        this.baseMapper.insert (activityUser);

    }

    //删除
    @Override
    public boolean delete(Integer id)

    {
        ActivityUser activityUser=null;
         activityUser = activityUserMapper.queryUsersId (id);
        if (activityUser != null) {
            activityUserMapper.updateBydel(id);
            return true;
        }
        return false;
    }


    //根据id修改密码
    @Override
    public void modifyIdPass(ModifyPassForm modifyPassForm) {
        activityUserMapper.modifyIdPass(modifyPassForm);
    }
}




